﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login : System.Web.UI.Page
{
    public LanguageManage Language;
    protected void Page_Load(object sender, EventArgs e)
    {
        Language = new LanguageManage();
    }
    protected void btLogin_Click(object sender, EventArgs e)
    {
        string username = txtUsername.Text;
        string password = txtPassword.Text;
        UserAdapter Auser = new UserAdapter();
        UserEntity usr = Auser.LoginWebApp(username, password);
        if (usr != null)
        {
            UserManager.Instance.Setuser(usr);
            if (UserManager.Instance.CheckDistributorAdminAuthen())
            {
                Response.Redirect("~/Home/Categories.aspx");
            }
            else if (UserManager.Instance.CheckDistributorPublisherAuthen())
            {
                if (usr.Active == true)
                {
                    Response.Redirect("~/Home/Categories.aspx");
                }
                else
                {
                    string mess = "<script type=\"text/javascript\">" + "alert('" + Language["ErrNotAtive"] + "');</" + "script>";
                    RegisterStartupScript("PopupScript", mess);
                }
            }

        }
        else
        {
            string mess = "<script type=\"text/javascript\">" + "alert('" + Language["Usernotexist"] + "');</" + "script>";
            RegisterStartupScript("PopupScript", mess);
        }
    }
}